<?php

namespace app\admin\model\patrol;

use think\Model;


class Child extends Model
{

    

    

    // 表名
    protected $name = 'patrol_child';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'supervisions_status_text',
        'status_text',
        'startime_text',
        'endtime_text',
        'endstatus_text'
    ];
    

    
    public function getSupervisionsStatusList()
    {
        return ['1' => __('Supervisions_status 1'), '2' => __('Supervisions_status 2')];
    }

    public function getStatusList()
    {
        return ['1' => __('待完成'), '2' => __('已完成')];
    }

    public function getEndstatusList()
    {
        return ['1' => __('Endstatus 1'), '2' => __('Endstatus 2'), '3' => __('Endstatus 3')];
    }


    public function getSupervisionsStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['supervisions_status']) ? $data['supervisions_status'] : '');
        $list = $this->getSupervisionsStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStartimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['startime']) ? $data['startime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEndstatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['endstatus']) ? $data['endstatus'] : '');
        $list = $this->getEndstatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setStartimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
